home *** CD-ROM | disk | FTP | other *** search
/ Programmers Heaven 2 / Programmers Heaven 2.iso / files / graphics / library / wgt51_r2.zip / WGT5 / H / WREND.H < prev   
Encoding:
C/C++ Source or Header  |  1996-08-03  |  9.1 KB  |  294 lines

  1. #ifndef _WREND_
  2. #define _WREND_
  3.  
  4. #include <wgt5.h>
  5.  
  6. /* 
  7.    WordUp Graphics Toolkit V5.0  Rendering Library
  8.    Copyright 1995 Egerter Software
  9. */
  10.  
  11. #ifdef __cplusplus
  12.   extern "C" {
  13. #endif
  14.  
  15.  
  16. /* Triangle Rendering Methods */
  17. #define WIREFRAME              0
  18. #define SOLID                  1
  19. #define GOURAUD                2
  20. #define TEXTURE                3
  21. #define FLAT_SHADED_TEXTURE    4
  22. #define GOURAUD_SHADED_TEXTURE 5
  23. #define TRANSLUCENT_TEXTURE    6
  24. #define TRANSLUCENT_GOURAUD    7
  25.  
  26.  
  27. #define M_PI 3.1415926535897932384626
  28.  
  29. #define POLYBUF  20000          /* Maximum polys per frame */
  30. #define OBJBUF     100          /* Maximum objects in world */
  31. #define MAXKEYS 100             /* Maximum animation keys per object */
  32. #define MAXCHILDREN 10          /* Maximum child objects per parent */
  33. #define MAX_TEXTURES 10         /* Maximum textures loaded at once */
  34.  
  35. extern float    render_shades;  /* Number of colors reserved for shading a 
  36.                                    single color */
  37. extern int      render_all;     /* 0 = backface removal */
  38.  
  39.  
  40. /* Our 3D system structures */
  41. typedef struct
  42. {
  43.   float         x, y, z;
  44. } point3d;                      /* A single 3D point */
  45.  
  46.  
  47. typedef struct
  48. {
  49.   point3d       local;
  50.   point3d       world;
  51.   point3d       normal;
  52.   int           screenx, screeny;
  53.   unsigned char connected;
  54.   unsigned char rotated;
  55. } vertex;                       /* A vertex of a polygon */
  56.  
  57.  
  58. typedef struct
  59. {
  60.   int           vertex1;
  61.   int           vertex2;
  62.   int           vertex3;
  63.   int           type;
  64.   point3d       normal;
  65.   point3d       center;
  66.   short         status;
  67.   unsigned char color;
  68. } triangle_3d;                   /* A 3D triangle */
  69.  
  70.  
  71. typedef struct
  72. {
  73.  float          sx, sy, sz; /* Scale */
  74.  float          tx, ty, tz; /* Translation */
  75.  float          rx, ry, rz; /* Rotation */
  76.  int            framenumber;
  77.  char           update_scale;
  78.  char           update_rotation;
  79.  char           update_translation;
  80. } keydata;                      /* Key animation data */
  81.  
  82.  
  83. typedef struct
  84. {
  85.   int           start_poly;
  86.   int           end_poly;
  87.   int           startpoints;
  88.   int           points;
  89.  
  90.   float         minx;
  91.   float         maxx;
  92.   float         miny;
  93.   float         maxy;
  94.   float         minz;
  95.   float         maxz;
  96.  
  97.   /* Added for animation */
  98.   float         translatex;
  99.   float         translatey;  /* Added to each vertex each frame */
  100.   float         translatez;
  101.  
  102.   float         pivotx;
  103.   float         pivoty;  /* Pivot location for this object */
  104.   float         pivotz;
  105.  
  106.   float         scalex;
  107.   float         scaley;  /* Multiplied by each vertex based on the distance */
  108.   float         scalez;  /* from the pivot location */
  109.  
  110.   float         rotatex;
  111.   float         rotatey;  /* Each vertex is rotated by this amount */
  112.   float         rotatez;
  113.  
  114.   /* Hierarchy */
  115.   short int     level;
  116.   short         maxchild;               /* Number of children */
  117.   unsigned short int children[MAXCHILDREN];
  118.   short         parent;                 /* Parent of this object */
  119.  
  120.   keydata       keylist[MAXKEYS];       /* Array of key frames */
  121.   int           maxframe;               /* Max animation frame */
  122.   int           currentframe;           /* Current animation frame */
  123.   
  124.   int           tstepsleft;             /* Translation steps left */
  125.   int           rstepsleft;             /* Rotation steps left */
  126.  
  127.   char          name[15];               /* Name of object */
  128. } object_3d;
  129.  
  130.  
  131. /* For shaded texture mapping */
  132. extern unsigned char *render_shadetable;
  133.  
  134. extern tpoint   renderpoly[3];  /* Used to draw one triangle at a time */
  135.  
  136. typedef struct {
  137.   int           number;                 /* Sorted polygon # */
  138.   float         depth;                  /* Center depth of polygon */
  139. } sort;
  140.  
  141. extern sort sorted_polys[POLYBUF];
  142.  
  143. typedef struct
  144. {
  145.  long           sx[3];
  146.  long           sy[3];
  147. } polytexture;
  148.  
  149. extern polytexture ptext[POLYBUF];      /* Holds texture coordinates for each
  150.                                            triangle in the polylist */
  151.  
  152. extern point3d  camera;                 /* Camera position */
  153. extern point3d  camera_norm;            /* Camera position */
  154. extern point3d  focus;                  /* Target position */
  155. extern point3d  tvect;                  /* Eye vector */
  156.  
  157. typedef struct {
  158.   point3d       world;
  159.   point3d       normal;
  160. } light;                                /* Light position */
  161.  
  162. extern float    fov;                    /* Field of view in degrees */
  163. extern float    dist;                   /* Distance from viewer */
  164. extern float    m11, m12, m21, m22, m23, m31, m32, m33;
  165.  
  166. extern triangle_3d polylist[POLYBUF];      /* Polygon list for world */
  167. extern object_3d objectlist[OBJBUF];     /* Object list for world */
  168.  
  169. extern block    textures[MAX_TEXTURES];
  170.  
  171. extern float    camera_x, camera_y, camera_z;
  172. extern float    focus_x, focus_y, focus_z;
  173. extern float    light_x, light_y, light_z;
  174. extern float    camera_angle;
  175. extern int      worldpoints;
  176. extern int      totalpoly;
  177. extern int      totalobjects;
  178.  
  179.  
  180. /* The following are defined in wrendani.c, used for moving, scaling, and 
  181.    rotating objects. */
  182. extern void translate_object (object_3d *obj, vertex *pts, float x, float y, 
  183.                               float z);
  184. /* Adds x,y,z to each 3D point in the object */
  185.  
  186.  
  187. extern void scale_object     (object_3d *obj, vertex *pts, 
  188.                               float x, float y, float z,
  189.                               float px, float py, float pz);
  190. /* Scales by x,y,z, based on the distance from px,py,pz */
  191.  
  192.  
  193. extern void rotate_object    (object_3d *obj, vertex *pts, 
  194.                               float x, float y, float z,
  195.                               float px, float py, float pz);
  196. /* Rotates the object by x,y,z around the center point px,py,pz */
  197.  
  198.  
  199. extern void set_object_pivot (object_3d *obj, float x, float y, float z);
  200. /* Sets x,y,z as the center of the object */
  201.  
  202.  
  203. extern void rotate_point (float *ptx, float *pty, float *ptz,
  204.                           float x, float y, float z,
  205.                           float px, float py, float pz);
  206. /* Rotates a single point by x,y,z around px,py,pz */
  207.  
  208.  
  209. /* The following are defined in wrend.c: */
  210.  
  211. extern void map_plane (float x, float y, float z, long *u, long *v, float scale);
  212. /* Given a 3D point, maps the point onto the x/y plane */
  213.  
  214. extern float dot_product (point3d *a, point3d *b);
  215. /* Compute the dot product between two 3D vectors */
  216.  
  217. extern void wset_focus (float a, float b, float c);
  218. /* Sets where the camera is looking at */
  219.  
  220. extern void wset_camera (float a, float b, float c);
  221. /* Sets the position of the camera */
  222.  
  223. extern void wset_light (float a, float b, float c);
  224. /* Sets the position of the light */
  225.  
  226. extern void wset_view (void);
  227. /* Sets up the viewing matrix based on the camera position and direction */
  228.  
  229. extern void wworld_2_view (object_3d *obj, int *drawtotal, vertex *vlist);
  230. /* Transform the 3D coordinates to 2D coordinates */
  231.  
  232. extern void calc_normal (vertex *wp1, vertex *wp2, vertex *wp3, point3d *norm);
  233. /* Calculates a normal vector given three vertices */
  234.  
  235. extern void map_points (short obj, vertex *pts, float scale);
  236. /* Map all the texture coordinates onto a plane, given an object and a scale */
  237.  
  238. extern int sortkeys (keydata *a, keydata *b);
  239. /* Sorts the animation keys by their frame number */
  240.  
  241. extern void adjust_object (object_3d *objp, float rx, float ry, float rz, 
  242.                     float px, float py, float pz);
  243. /* Modify an object's animation data if it has a parent */
  244.  
  245. extern void duplicate_frame (object_3d *obj, int frame, int framenumber);
  246. /* Copies one animation key to another */
  247.  
  248. extern void build_hierarchy (void);
  249. /* Connects children and parents together */
  250.  
  251. extern void add_key_translate (object_3d *obj, int framenumber, float x, float y, 
  252.                         float z);
  253. /* Adds a translation animation key */
  254.  
  255. extern void add_key_scale (object_3d *obj, int framenumber, float x, float y,
  256.                     float z);
  257. /* Adds a scale animation key */
  258.  
  259. extern void add_key_rotate (object_3d *obj, int framenumber, float x, float y, 
  260.                     float z);
  261. /* Adds a rotation animation key */
  262.  
  263. extern int find_object (char *name);
  264. /* Given the name of an object, returns the index in objectlist */
  265.  
  266. extern void add_child (int parent, int child);
  267. /* Adds a child to a parent object */
  268.  
  269. extern void load_3ds (char *filename, vertex *pts);
  270. /* Loads a 3D Studio file */
  271.  
  272. extern int compare (sort *a, sort *b);
  273. /* Used for sorting */
  274.  
  275. extern void draw_polys (vertex *pts, int drawtotal);
  276. /* Draws the polygons */
  277.  
  278. extern void wset_object_color (int obj, unsigned char col);
  279. /* Sets the color of each triangle in an object, used for solid, gouraud, and
  280.    texture.  For textured objects, the color represents the texture number
  281.    from the textures array. */
  282.  
  283. extern void wset_object_type (int obj, int type);
  284. /* Sets the rendering method for an object */
  285.  
  286. extern void wreset_3d_system (void);
  287. /* Resets the engine so you can load in a new object */
  288.  
  289. #ifdef __cplusplus
  290. }
  291. #endif
  292.  
  293. #endif
  294.